function sampleVec=createSampleVector(beginDate,endDate) 
% Create a sample vector by providing the strings beginDate and endDate 
% Can either be monthly, e.g. 2010m2, quarterly, e.g. 2010q1 or yearlt 2010
% 
if ~ischar(beginDate) 
    error('Begin Date must be a string') 
end 
if ~ischar(beginDate) 
    error('Begin Date must be a string') 
end 
findMonth=findstr(upper(beginDate),'M'); 
findQuarter=findstr(upper(beginDate),'Q'); 
if ~isempty(findMonth);
    caseFrequency=2;
else
    if ~isempty(findQuarter)
    caseFrequency=1; 
    else 
        caseFrequency=3; 
    end 
end 
switch caseFrequency
    case 1 % Quarterly 
        [yearBegin,periodBegin]=extractYearSubperiod(beginDate,findQuarter);
        [yearEnd,periodEnd]=extractYearSubperiod(endDate,findstr(upper(endDate),'Q'));
        Nperiods=4;
    case 2 % Monthly 
        [yearBegin,periodBegin]=extractYearSubperiod(beginDate,findMonth);
        [yearEnd,periodEnd]=extractYearSubperiod(endDate,findstr(upper(endDate),'M'));
        Nperiods=12;
    case 3 % Yearly 
       yearBegin=str2num(beginDate); 
       yearEnd  =str2num(endDate);
       sampleVec=yearBegin:yearEnd; 
end
if caseFrequency~=3
    a=yearBegin+(periodBegin-1)/Nperiods;
    b=yearEnd+(periodEnd-1)/Nperiods;
    sampleVec=a:1/Nperiods:b;
end
end

function [y,z]=extractYearSubperiod(x,frequencyPosition)
y=str2num(x(1:frequencyPosition-1));
z=str2num(x(frequencyPosition+1:end));
end
